﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.LogEntries.MakePeaceLogEntry
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using Helpers;
using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.LogEntries
{
  public class MakePeaceLogEntry : LogEntry, IEncyclopediaLog, IChatNotification
  {
    [SaveableField(240)]
    public readonly IFaction Faction1;
    [SaveableField(241)]
    public readonly IFaction Faction2;

    internal static void AutoGeneratedStaticCollectObjectsMakePeaceLogEntry(
      object o,
      List<object> collectedObjects)
    {
      ((LogEntry) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this.Faction1);
      collectedObjects.Add((object) this.Faction2);
    }

    internal static object AutoGeneratedGetMemberValueFaction1(object o)
    {
      return (object) ((MakePeaceLogEntry) o).Faction1;
    }

    internal static object AutoGeneratedGetMemberValueFaction2(object o)
    {
      return (object) ((MakePeaceLogEntry) o).Faction2;
    }

    public bool IsVisibleNotification => true;

    public override CampaignTime KeepInHistoryTime => CampaignTime.Days(40f);

    public MakePeaceLogEntry(IFaction faction1, IFaction faction2)
    {
      this.Faction1 = faction1;
      this.Faction2 = faction2;
    }

    public override int GetAsRumor(Settlement talkSettlement, ref TextObject comment)
    {
      if (this.Faction1 == talkSettlement.MapFaction)
      {
        comment = new TextObject("{=wfb0FnbW}At last they've made peace with {ENEMY_NAME}. Good. I hope it lasts.");
        comment.SetTextVariable("ENEMY_NAME", FactionHelper.GetTermUsedByOtherFaction(this.Faction2, talkSettlement.MapFaction, false));
        return 10;
      }
      if (this.Faction2 != talkSettlement.MapFaction)
        return 0;
      comment = new TextObject("{=94wCiGjB}So it seems as though {ENEMY_NAME} have had enough of war. Good. Peace is good.");
      comment.SetTextVariable("ENEMY_NAME", FactionHelper.GetTermUsedByOtherFaction(this.Faction1, talkSettlement.MapFaction, false));
      return 10;
    }

    public override string ToString() => this.GetEncyclopediaText().ToString();

    public TextObject GetNotificationText()
    {
      TextObject text = GameTexts.FindText("str_notification_secondary_peace");
      text.SetTextVariable("FACTION1", this.Faction1.InformalName);
      text.SetTextVariable("FACTION2", this.Faction2.InformalName);
      return text;
    }

    public bool IsVisibleInEncyclopediaPageOf<T>(T obj) where T : MBObjectBase
    {
      return (object) obj == this.Faction1 || (object) obj == this.Faction2;
    }

    public override ChatNotificationType NotificationType
    {
      get => this.DiplomaticNotification(this.Faction1, this.Faction2);
    }

    public TextObject GetEncyclopediaText()
    {
      TextObject text = GameTexts.FindText("str_factions_make_peace_news");
      text.SetTextVariable("FACTION1", this.Faction1.EncyclopediaLinkWithName);
      text.SetTextVariable("FACTION2", this.Faction2.EncyclopediaLinkWithName);
      return text;
    }
  }
}
